package com.atguigu.gmall.search.controller;

import com.atguigu.gmall.common.bean.ResponseVo;
import com.atguigu.gmall.search.service.SearchService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchResponseVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Arrays;

/**
 * @Author zhaoshuo
 * @ClassName SearchController
 * @Description
 */
@Controller
@RequestMapping("search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @ApiOperation("搜索页条件查询es数据")
    @GetMapping
    public String search(SearchParamVo paramVo, Model model) {
        SearchResponseVo response = searchService.search(paramVo);
        model.addAttribute("response", response);
        model.addAttribute("searchParam", paramVo);
        return "search";
    }


    @GetMapping("hello.html")
    public String hello(Model model, HttpSession session) {
        model.addAttribute("k1", "v1");
        model.addAttribute("k2", ResponseVo.fail("k2.msg"));
        model.addAttribute("k3", Arrays.asList(ResponseVo.ok("k3.1"), ResponseVo.fail("k3.2"), ResponseVo.ok("k3.3")));
        session.setAttribute("k4", "v4");
        return "hehe";
    }
}